var app = getApp();
Page({
  data: {
    userInfo: [],
    wechat: "",
    tanchuang_css: "display:none;",
    textarea_css: ""
  },
  onLoad: function () {
    this.setData({
      userInfo: app.globalData.userInfo
    })
  },
  onShow: function () {
    this.setData({
      tanchuang_css: "display:none;",
      textarea_css: ""
    })
  },
  onReady: function () {
    var that = this;
    wx.request({
      url: app.globalData.API_Base_URL + "/data/index/getDaiLiWeChat",
      success: function (res) {
        that.setData({
          wechat: res.data
        })
      }
    })
  },
  zhaohezuo: function (e) {
    var that = this;
    if (e.detail.value.info.replace(/(^\s*)|(\s*$)/g, "") == "") {
      wx.showToast({
        title: '请输入代理申请说明',
        image: "../../image/cancel.png",
      })
    } else {
      wx.showLoading({
        title: '上传中',
        duration: 100000,
      })
      var data = [];
      data["openid"] = app.globalData.openid;
      data["name"] = this.data.userInfo.nickname;
      data["phone"] = this.data.userInfo.mobile;
      data["wechat"] = this.data.userInfo.email;
      data["info"] = e.detail.value.info;

      data["name"] = data["name"].replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g, "");
      data["info"] = data["info"].replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g, "");

      wx.request({
        url: app.globalData.API_Base_URL + "/dailishengqing/index/dailishengqing",
        data: data,
        success: function (res) {
          if (res.data == 0) {
            wx.showToast({
              title: '已提交',
              duration: 1500,
              success: function () {
                setTimeout(function(){
                  that.setData({
                    tanchuang_css: "",
                    textarea_css: "margin: 0 0 0 -10000000000rpx;"
                  })
                },1500);
              }
            })
          } else {
            wx.showToast({
              title: '上传失败',
              image: "../../image/cancel.png",
              duration: 800
            })
          }
        }
      })
    }
  },
  //复制
  copy_wechat: function () {
    var that = this
    wx.setClipboardData({
      data: that.data.wechat,
    })
    wx.showToast({
      title: '复制成功',
      icon: 'success',
      duration: 300
    });
  },
  hideTanChuang: function () {
      wx.navigateBack({
        data: 1
      })
  }
})